//
//  XLTextField.m
//  campus
//
//  Created by xl on 2019/11/11.
//  Copyright © 2019 xl. All rights reserved.
//

#import "XLTextField.h"

@interface XLTextField()
@property (nonatomic, assign) BOOL canPaste;//是否能粘贴 默认YES

@end

@implementation XLTextField

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.canPaste = YES;
    }
    return self;
}

- (void)changLineSpacing
{
    [self changLineSpacing:10 fontSize:15];
}

- (void)changLineSpacing:(CGFloat)padding fontSize:(CGFloat)fontSize
{
    // 判断是否有候选字符，如果不为nil，代表有候选字符
    if(self.markedTextRange == nil){
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = padding; // 字体的行间距
        paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
        
        NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize],
                                     NSParagraphStyleAttributeName:paragraphStyle
                                     };
        self.attributedText = [[NSAttributedString alloc] initWithString:self.text attributes:attributes];
    }
}

- (void)setCurrentTextFiledCanPaste:(BOOL)paste
{
    self.canPaste = paste;
}

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(paste:))//禁止粘贴
        return self.canPaste;
//    if (action == @selector(select:))// 禁止选择
//        return NO;
//    if (action == @selector(selectAll:))// 禁止全选
//        return NO;
    return [super canPerformAction:action withSender:sender];
    
}

@end
